home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Serious Demos / Portfolio 4.0.1 / Scripting Extras / Move DCS Plates.txt < prev    next >
Text File  |  1998-09-15  |  3KB  |  74 lines

  1. -- 1.01 - Check to make sure Portfolio is running
  2. tell application "Finder"
  3.     set P_app to every process whose name contains "Portfolio"
  4.     if P_app is {} then
  5.         display dialog ¬
  6.             "Portfolio must be running for this script to operate." buttons {"OK"} default button {"OK"}
  7.         return
  8.     end if
  9. end tell
  10.  
  11.  
  12. set countMoved to 0
  13.  
  14. tell application "Portfolio"
  15.     -- Go to Portfolio and find out how many items are selected in the current gallery.
  16.     set theCount to count every record of selection of front gallery
  17.     
  18.     -- If no items are selected, we need to ask the user to select something and then quit.
  19.     if theCount = 0 then
  20.         display dialog ¬
  21.             "Please select one or more items in the gallery and rerun the command." buttons {"OK"} default button {"OK"}
  22.         return
  23.     end if
  24.     
  25.     -- Get the first record of the selection. We'll ignore the rest.
  26.     set fName to field "path" of first record of the selection of front gallery
  27. end tell
  28.  
  29. -- Parse Portfolio's path if it is up on a server to strip the server name.
  30. if fName starts with "::" then
  31.     set the text item delimiters to {":"}
  32.     set argCnt to (the count of text items in fName)
  33.     set fName to (text items 4 through argCnt in (fName)) as string
  34. end if
  35.  
  36. --Get the destination folder
  37. set newFolder to choose folder with prompt "Select the destination folder:"
  38.  
  39. -- Figure out if the original file name has an extension
  40. set text item delimiters to "."
  41. set lParsed to every text item of fName
  42. if the (count of lParsed) > 1 then
  43.     set fRoot to items 1 thru ((count of lParsed) - 1) of lParsed as string
  44. else
  45.     set fRoot to lParsed as string
  46. end if
  47.  
  48. -- Build up a list of the five possible files
  49. set leList to {fName as string, fRoot & ".C", fRoot & ".M", fRoot & ".Y", fRoot & ".K"}
  50.  
  51. -- Iterate through the list, check if the file exists, and if it does, move it to the new location.
  52. repeat with fFile in leList
  53.     set fFile to fFile as string -- Coerce the list item to a string
  54.     tell application "Finder"
  55.         if (exists of file fFile) then
  56.             move file fFile to folder newFolder
  57.             set countMoved to countMoved + 1
  58.         end if
  59.     end tell
  60. end repeat
  61.  
  62. -- Build the name for the composite file at its new location
  63. set text item delimiters to ":"
  64. set fComposite to the last text item of fName as string
  65. set newPath to (newFolder as string) & fComposite
  66.  
  67. --Update the Portfolio location for that item
  68. tell application "Portfolio"
  69.     set path of first record of the selection of front gallery to newPath
  70. end tell
  71.  
  72. -- Tell the user the results
  73. display dialog "Results:" & return & countMoved & ¬
  74.     " out of 5 files were successfully moved." buttons {"OK"}